package com.example.myproject.demo.controller;

import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.example.myproject.demo.User;
import com.example.myproject.springdemo.aop.IHelloAop;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;

/**
 * Created by Mj on 2018/5/3.
 */
@RestController
@RequestMapping(value = "/test")
public class DemoController {

    @Autowired
    private IHelloAop helloAop;

    @RequestMapping("/hello")
    public int hello(@RequestBody ReuqestJsonBean reuqestJsonBean) throws InterruptedException {
        ;
//        request.getSession().setAttribute("name","OYangFeng");
//
//        Thread.sleep(3000);
//        helloAop.helloWorld("I am a person");
        return reuqestJsonBean.getTestBeans().length;
    }
    @RequestMapping("/getDate")
    public int getDate(@RequestBody User[] users){
        System.out.println(users.length);
        return users.length;
    }
    @RequestMapping(value = "/name",method = RequestMethod.PATCH)
    public TestBean patchName(HttpServletRequest request){
        TestBean testBean = new TestBean();
        testBean.setAge(10);
        testBean.setName("PATCH");
        return testBean;
    }
    @RequestMapping(value = "/name",method = RequestMethod.POST)
    public String postName(HttpServletRequest request){
        return "LUO GG .....POST";
    }
    @RequestMapping(value = "/name",method = RequestMethod.GET)
    public TestBean getName(HttpServletRequest request){
        TestBean testBean = new TestBean();
        testBean.setAge(10);
        testBean.setName("GET");
        return testBean;

    }
    @RequestMapping(value = "/name",method = RequestMethod.DELETE)
    public TestBean name(HttpServletRequest request){
        TestBean testBean = new TestBean();
        testBean.setAge(10);
        testBean.setName("DELETE");
        return testBean;
    }

    @RequestMapping("/rest")
    public String restTest(@RequestBody User user){

        return "hello , Mis "+user.getUsername();
    }


    @RequestMapping(value = "/getRest",method = RequestMethod.GET)
    public String getRest(){
        return "getRest";
    }



    @RequestMapping(value = "/getRest/{id}",method = RequestMethod.GET)
    public String getRestId(@PathVariable String id){
        return "getRest"+id;
    }
}
